package com.yb.project.system.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yb.framework.security.utils.SecurityUtil;
import com.yb.project.base.controller.BaseController;
import com.yb.project.system.domain.SysMenu;

@Controller
public class IndexController extends BaseController {
	
	/**
	 * 主页面、一级目录
	 */
	@GetMapping("/index")
	public String toIndex(Model model) {
		List<SysMenu> sysMenuList = new ArrayList<SysMenu>();
		if(SecurityUtil.isAdmin()) {
			sysMenuList = sysMenuService.getListByParamMap(0L, 1);
		} else {
			sysMenuList = sysMenuService.getListByParamMap(0L, 1, SecurityUtil.getAuthorities());
		}
		model.addAttribute("sysMenuList", sysMenuList);
		return "index";
	}
	
	/**
	 * 二级目录
	 */
	@GetMapping(value = "/menu/left_2/{pid}")
	public @ResponseBody List<SysMenu> left_2(@PathVariable Long pid) {
		List<SysMenu> sysMenuList = new ArrayList<SysMenu>();
		if(SecurityUtil.isAdmin()) {
			sysMenuList = sysMenuService.getListByParamMap(pid, 2);
		} else {
			sysMenuList = sysMenuService.getListByParamMap(pid, 2, SecurityUtil.getAuthorities());
		}
		return sysMenuList;
	}
	
	/**
	 * 三级目录
	 */
	@GetMapping(value = "/menu/left_3/{pid}")
	public @ResponseBody List<SysMenu> left_3(@PathVariable Long pid) {
		List<SysMenu> sysMenuList = new ArrayList<SysMenu>();
		if(SecurityUtil.isAdmin()) {
			sysMenuList = sysMenuService.getListByParamMap(pid, 3);
		} else {
			sysMenuList = sysMenuService.getListByParamMap(pid, 3, SecurityUtil.getAuthorities());
		}
		return sysMenuList;
	}
}
